from multiprocessing import Process
from os import getpid
from random import randint
from time import time, sleep


def download_task(fileName):
    print('启动下载，进程为[%d]。' % getpid())
    print('启动下载%s。。。' % fileName)
    time_to_download = randint(5, 10)
    sleep(time_to_download)
    print('%s 下载完成！耗时%d秒' % (fileName, time_to_download))


def main():
    start = time()
    p1 = Process(target=download_task, args=('python从入门到入土,',))
    p1.start()
    p2 = Process(target=download_task, args=('java 从入门到放弃。avi'))
    p2.start()
    p1.join()
    p2.join()
    end = time()
    print('一共耗时%.2f秒。' % (end - start))


if __name__ == "__main__":
    main()